﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using XProject.DataVisit.Model;
using NHibernate;
using NHibernate.Criterion;
using XProject.DataVisit.BLL;

namespace XProject.DataVisit.DAL.BaseManager
{
    public class DUserInfo:AbstractSupportDal<UserInfo>
    {
        public UserInfo GetByNameAndPass(string name, string pass)
        {
            var t = new UserInfo();
            Template.Execute(delegate(ISession session) {
                t=session.CreateCriteria<UserInfo>()
                    .Add(Expression.Eq("UserAccount", name))
                    .Add(Expression.Eq("UserPass", PublicFn.getMD5(pass)))
                    .UniqueResult<UserInfo>();
                return t;
            });
            return t;
        }
        public UserInfo GetByNameAndPass_NoMD5(string name, string pass)
        {
            var t = new UserInfo();
            Template.Execute(delegate(ISession session)
            {
                t = session.CreateCriteria<UserInfo>()
                    .Add(Expression.Eq("UserAccount", name))
                    .Add(Expression.Eq("UserPass", pass))
                    .UniqueResult<UserInfo>();
                return t;
            });
            return t;
        }

        public IList<UserInfo> GetListData()
        {
            IList<UserInfo> t = new List<UserInfo>();
            Template.Execute(delegate(ISession session)
            {
                t = session.CreateCriteria<UserInfo>()
                    .List<UserInfo>();
                return t;
            });
            return t;
        }

        public UserInfo GetOneData(Guid roleid)
        {
            UserInfo user = new UserInfo();
            IList<UserInfo> t = new List<UserInfo>();
            Template.Execute(delegate(ISession session)
            {
                t = session.CreateCriteria<UserInfo>()
                    .Add(Restrictions.Eq("RoleID", roleid))
                    .List<UserInfo>();
                if (t.Count > 0)
                {
                    user = t[0];
                }
                return user;
            });
            return user;
        }
    }
}
